package com.atguigu.linklist;

public class FindTheEntranceOfRing {
    public ListNode entryNodeOfLoop(ListNode head){
        if(head==null){
            return null;
        }
        if(head.next==null){
            return null;
        }
        ListNode fast=head;
        ListNode slow=head;
        while(fast!=null && fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            if(slow==fast){
                break;
            }
        }
        if(fast==null){
            return null;
        }
        fast=head;
        while(fast!=slow){
            fast=fast.next;
            slow=slow.next;
        }
        return fast;
    }
}
